package testDemo.UDPTest;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.*;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

class Send {
    public static void main(String[] args) throws IOException {
        DatagramSocket ds = new DatagramSocket();
        BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
        String line;
        while((line=br.readLine())!=null){
            if("886".equals(line)){
                break;
            }
            DatagramPacket dp = new DatagramPacket(line.getBytes(),line.length(),InetAddress.getByName("127.0.0.1"),10086);
            ds.send(dp);
        }
//        ds.close();
    }
}
class Receive {
    public static void main(String[] args) throws IOException {
        DatagramSocket ds = new DatagramSocket(10086);
        while(true){
            byte[] bytes = new byte[1024];
            DatagramPacket dp = new DatagramPacket(bytes, bytes.length);
            ds.receive(dp);
            System.out.println("接收的数据是："+new String(dp.getData(),0,dp.getLength()));
        }
//        ds.close();
    }
}
